package com.itheima;


import com.itheima.demo01lambda.Person;
import org.junit.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Arrays;
import java.util.Date;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

@SpringBootTest
public class test01 {
    //对象名::引用成员方法
    @Test
    public void test01(){
        Date date = new Date();
        Supplier<Long> supplier2 = date::getTime;
        System.out.println(supplier2.get());
    }

    //类名::引用静态方法
    @Test
    public void test02() {
        Supplier<Long> supp2 = System::currentTimeMillis;
        System.out.println(supp2.get());
    }

    //类名::引用实例方法
    @Test
    public void test03() {
        Function<String, Integer> f1 = (s) ->{
            return s.length();
        };

        System.out.println(f1.apply("abc"));
        Function<String, Integer> f2 = String::length;
        BiFunction<String, Integer, String> bif = String::substring;
        String hello = bif.apply("hello", 2);
        System.out.println("hello = " + hello);
    }

    //类名::new引用构造器
    @Test
    public void test04(){
        Supplier<Person> sup2 = Person::new;
        System.out.print(sup2.get());
    }

    //数组::new 引用数组构造器
    @Test
    public void test05(){
        Function<Integer,String[]> function = String[]::new;
        String[] arr2 = function.apply(5);
        Arrays.stream(arr2).forEach(System.out::println);
    }

}
